<template>
	<view>
		<nav_bar title='搜索'></nav_bar>
		<view style="padding-top: 60px;">

			<uni-search-bar :focus="true" v-model="searchValue" @input="input" >

			</uni-search-bar>
			<view class="search-result">
				<text class="search-result-text">当前输入为：{{ searchValue }}</text>
			</view>
		</view>
		<view class="Product_list">
			<dl v-for="(item,index) in list" :key="index">
				<dt><img :src="item.logo" alt="" /></dt>
				<dd>
					<view class="title">
						<p class="brand">品牌</p>
						<h3>{{item.shopname}}</h3><span>4.8分</span>
					</view>
					<b class="Guaranteed_ticket">保准票</b>
					<uni-rate allow-half :value="item.score" />
					<view style="display: flex;">
						<p class="Monthly_sales">月售106单</p>
						<p class="describe">{{item.content}}</p>
					</view>
					<p class="Delivery_fee">{{item.fee}}￥起送/配送费5￥</p><span class="Starting">起点转送</span>
				</dd>
			</dl>
		</view>
	</view>
</template>

<script>
	import {
		ipconfig
	} from '../../ipconfig.js'
	export default {
		data() {
			return {
				searchValue: '',
				list: [],
				originalList: [], // 保存原始数据，用于搜索
			}
		},
		methods: {
			input(res) {
				console.log('----input:', res)
				const keyword = res; // 获取搜索框的值

				if (keyword.trim() === '') { // 如果搜索框的值为空，则展示所有数据
					this.list = this.originalList;
					return;
				}

				// 根据搜索框的值进行过滤数据
				this.list = this.originalList.filter(item => {
					// 这里可以根据你的具体需求进行匹配条件的定义
					// 这里假设要匹配品牌名称
					return item.shopname.includes(keyword);
				});
			}
		},
		onLoad() {
			let _this = this;
			uni.request({
				url: `http://${ipconfig}:8002/admin/shoplists`, //仅为示例，并非真实接口地址。
				method: 'get',
				success: (res) => {
					console.log(res.data, '商品数据');
					_this.list = res.data;
					_this.originalList = res.data; // 将原始数据保存起来
				}
			});
		}
	}
</script>

<style scoped lang="scss">
	.search-result {
		padding-top: 10px;
		padding-bottom: 20px;
		text-align: center;
	}

	.search-result-text {
		text-align: center;
		font-size: 14px;
		color: #666;
	}

	.Product_list {
		// background: pink;
		width: 100%;

		dl {
			width: 100%;
			height: 110px;
			// background: greenyellow;
			border-top: 1px solid #ccc;
			// border-bottom: 1px solid #ccc;
			display: flex;
			cursor: pointer;

			dt {
				img {
					width: 80px;
					height: 80px;
					border-radius: 8px;
					display: inline-block;
					margin: 10px;
				}
			}

			dd {
				// background: pink;
				width: 72%;
				position: relative;

				.title {
					display: flex;
					// background: pink;
					width: 200px;
					justify-content: space-between;
					margin-top: 10px;
					align-items: center;

					span {
						color: red;
						font-size: 12px;
						font-weight: 900;
					}

					.brand {
						width: 40px;
						height: 20px;
						background: #FFD930;
						text-align: center;
						border-radius: 5px;
					}
				}

				.Guaranteed_ticket {
					position: absolute;
					right: 5px;
					top: 10px;
					color: #949494;
				}

				.Monthly_sales {
					color: #868686;
					font-size: 12px;
				}

				.describe {
					margin-left: 10px;
					color: #02A774;
				}

				.Delivery_fee {
					color: #666666;
					display: inline-block;
				}

				.Starting {
					float: right;
					font-size: 12px;
					border: 2px solid #4FBC9B;
					border-radius: 5px;
					color: #02A774;
					margin-right: 5px;
				}
			}
		}

	}
</style>